Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Screener Feature #2066

Merged
merged 2 commits into from
Oct 19, 2024
Merged

Implement Screener Feature #2066

merged 2 commits into from
Oct 19, 2024

Conversation

ericpien
Copy link
Contributor

@ericpien ericpien commented Oct 1, 2024

Screener can be used to filter securities on yahoo finance. This can be used to get the top gainers of the day, and more customized queries that a user may want to automate.

  • Add a new class Screener, Query, and EquityQuery
  • EquityQuery extends Query such that other types of query can be implemented in the future (i.e. Funds)
  • Refactor YfData.get() to enable YfData.post() to all of get's implementations
  • Add test for the Screener
  • Add new set and map to const

Resolves:

import yfinance as yf
screener = yf.Screener()
screener.set_predefined_body('day_gainers')
result = screener.response

Sample Code

import yfinance as yf

# Example query to filter stocks
gt = yf.EquityQuery('gt', ['eodprice', 3])
lt = yf.EquityQuery('lt', ['avgdailyvol3m', 99999999999])
btwn = yf.EquityQuery('btwn', ['intradaymarketcap', 0, 100000000])
eq = yf.EquityQuery('eq', ['sector', 'Technology'])

# Combine queries using AND/OR
qt = yf.EquityQuery('and', [gt, lt])
qf = yf.EquityQuery('or', [qt, btwn, eq])

# Create a screener instance
screener = yf.Screener()

# Set the default body using a custom query
screener.set_default_body(qf)

# Set predefined body
screener.set_predefined_body('day_gainers')

# Set the fully custom body 
# The keys below are required fields for the request body
screener.set_body({
    "offset": 0,
    "size": 100,
    "sortField": "ticker",
    "sortType": "desc",
    "quoteType": "equity",
    "query": qf.to_dict(),
    "userId": "",
    "userIdType": "guid"
})

# Patch parts of the body
screener.patch_body({"offset": 100})

# view the current body of the screener
screener.body

# Fetch and display the result json
result = screener.response
print(results)

# save the queried symbols
symbols = [quote['symbol'] for quote in result['quotes']]

- Add a new class Screener, Query, and EquityQuery
- Refactor YfData.get() to enable YfData.post() to all of get's implementations
- Add test for the Screener
- Add new set and map to const

Screener can be used to filter yahoo finance. This can be used to get the top gainers of the day, and more customized queries that a user may want to automate.
@ericpien ericpien marked this pull request as ready for review October 1, 2024 01:02
@ValueRaider
Copy link
Collaborator

Do you think the README is getting too long now and needs to offload some content to a new home?

@ericpien
Copy link
Contributor Author

ericpien commented Oct 4, 2024

Do you think the README is getting too long now and needs to offload some content to a new home?

I agree. As part of the offloading, I think creating a \doc directory and adding api specific documentation in there would be great for new users and contributors.

Idk what you have in mind but maybe something like below?

doc/
├── CHANGELOG.rst
└── api/
    ├── Ticker
    ├── Sector_Industry
    ├── Screener
    └── General # caching, logging, managing multi-level columns

@ValueRaider
Copy link
Collaborator

Move doc discussion to #1330

@ericpien
Copy link
Contributor Author

@ValueRaider I suspect you've just been busy but in case you lost track, can you review the remainder of the code when you get a chance? I also provided a draft of documentation at #1330 (reply in thread)

@ValueRaider
Copy link
Collaborator

Replace the README addition with essentially:

  • a few key lines
  • "ToDo: link to Github Page for more"

Then I can merge and we sort out documentation later. Don't rebase this time, so we can reuse c048378

- Reduce the information provided in README with the expectation of migrating to separate documentation.
@ValueRaider ValueRaider merged commit 4672715 into ranaroussi:dev Oct 19, 2024
2 checks passed
@ValueRaider ValueRaider mentioned this pull request Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants